{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Replacing a Car\n", "## Problem definition\n", "At the beginning of each year, a car is in good, regular or bad state: \n", "\n", "- There is a 90% probability that a good car will be in a good state at the beginning of next year \n", "\n", "- There is a 5% probability that it will be in a regular state\n", "\n", "- and a 5 % probability that it will be in bad state. \n", "\n", "If a car is in a regular state, then:\n", "\n", "- There is a 70 % probability that the car is in again in regular state at the beginning of next year,\n", "- and a 30 % probability that it will be in a bad state.\n", "\n", "A bad car has no sale value and must be immediately replaced with a good one.\n", "\n", "It costs €12,000 to buy a good car, but a regular one can be found for €5,000.\n", "Maintenance costs are €1,000/year for a good car and €2,000 for a regular car, and must be paid upfront at the beginning of the year.\n", "\n", "Must I replace my car as soon as it is in a regular state, or must I wait until it is in a bad state?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution\n", "We can model the status of the car at the beginning of the next year as a Markov system, with three possible states: \n", "\n", "- $s_1$: represents the car being in good state.\n", "- $s_2$: represents the car being in regular state. \n", "- $s_2$: represents the car being in bad state.\n", "\n", "With this model, we have to evaluate two possible scenarios. If we let the car transition to the regular state, the one-step transition probability matrix is: \n", "\n", "$P^{(1)} = \\begin{bmatrix}\n", "0.9 & 0.05 & 0.05\\\\\n", "0 & 0.7 & 0.3 \\\\\n", "0.9 & 0.05 & 0.05\n", "\\end{bmatrix}$\n", "\n", "Since a bad car needs to be replaced immediately, even if the event occurs in the last day of the year, a car in a bad status is always replaced by a new one before the beginning of the next year, and therefore the transition probabilities are the same as for a new car.\n", "\n", "Now, if we replace the car immediately as soon as it is in a regular state, the one-step probability matrix becomes:\n", "\n", "$P^{(1)} = \n", "\\begin{bmatrix}\n", "0.9 & 0.05 & 0.05\\\\\n", "0.9 & 0.05 & 0.05\\\\\n", "0.9 & 0.05 & 0.05\n", "\\end{bmatrix}$\n", "\n", "That is, as soon as the car is in a regular state, it is replaced by a new one. \n", "We have thus two different scenarios, and each step has different associated in each scenario.\n", "\n", "We can calculate the stationary probabilities and corresponding long term average costs. In scenario 1, the long term probabilities are: \n", "\n", "$\\pi_1 = 0.771429$\n", "\n", "$\\pi_2 = 0.142857$\n", "\n", "$\\pi_3 = 0.0857143$\n", "\n", "In this scenario the costs are:\n", "\n", "- $C_1$: 1000€ maintenance cost of a good car.\n", "- $C_2$: 2000€ maintenance cost of a regular car.\n", "- $C_2$: 13000€ cost of purchasing a new car plus year maintenance costs.\n", "\n", "The long term average cost is: \n", "\n", "$C = \\sum_i{C_i·\\pi_i} = 2,171$\n", "\n", "In the second scenario:\n", "\n", "$\\pi_1 = 0.9$\n", "\n", "$\\pi_2 = 0.05$\n", "\n", "$\\pi_3 = 0.05$\n", "\n", "In this scenario the costs are: \n", "- $C_1$: 1000€ maintenance cost of a good car.\n", "- $C_2$: 8000€ cost of purchasing a new car plus year maintenance cost minus costs of selling a regular car.\n", "- $C_2$: 13000€ cost of purchasing a new car plus year maintenance costs.\n", "\n", "We can calculate the long term average cost again as: \n", "\n", "$C = \\sum_i{C_i·\\pi_i} = 1950$\n", "\n", "So, under these conditions, the second scenario provides a lower long term average cost" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }